﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess.DataObject;

namespace DataAccess.BusinessObject
{
    public class BCoupon_Product:Common.CDBase
    {
        /// <summary>
        /// Add Product to Coupon
        /// </summary>
        /// <param name="Coupon"></param>
        /// <param name="IDProduct"></param>
        /// <returns></returns>
        public bool Add(int IDCoupon, int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDCoupon",SqlDbType.Int),
                                        new SqlParameter("@IDProduct",SqlDbType.Int)};
            sqlParam[0].Value = IDCoupon;
            sqlParam[1].Value = IDProduct;
            return RunProcedure("sp_tblCoupon_Product_add", sqlParam);
        }
        /// <summary>
        /// Remove Product Coupon
        /// </summary>
        /// <param name="IDProduct"></param>
        /// <returns></returns>
        public bool Delete(int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int) };
            sqlParam[0].Value = IDProduct;
            return RunProcedure("sp_tblCoupon_Product_delete", sqlParam);
        }

        public int CountProduct(int CouponID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDCoupon", SqlDbType.Int) };
            sqlParam[0].Value = CouponID;
            DataTable dtb = RunProcedureGet("sp_tblCoupon_Product_count", sqlParam);
            return int.Parse(dtb.Rows[0]["Count"].ToString());
        }
        /// <summary>
        /// Get Coupon OF product
        /// </summary>
        /// <param name="IDProduct"></param>
        /// <returns></returns>
        public IList<OCoupon_Product> Get(int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int) };
            sqlParam[0].Value = IDProduct;
            return Common.Common.ConvertTo<OCoupon_Product>(RunProcedureGet("sp_tblCoupon_Product_get", sqlParam));
        }
    }
}
